Shader "geometry/geoPointMove"
{
    Properties
    {
        _NoiseTex ("NoiseTex", 2D) = "white" {}
        _NoiseStrength ("NoiseStrength", int) = 3
        _BaseColor("Base Color", Color) = (0, 1, 0, 1)
        _Speed("Speed", Range(0,10)) = 2
        _Move("Speed", Vector) = (5, 5, 5, 0)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma geometry geom
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float4 normal : NORMAL;
                float2 uv : TEXCOORD0;
            };

            struct v2g
            {
                float4 vertex : SV_POSITION;
                float4 color : COLOR;
                float2 uv : TEXCOORD0;
                float progress : TEXCOORD1;
            };

            struct g2f 
            { 
                float2 uv : TEXCOORD0; 
                float4 vertex : SV_POSITION; 
                float progress : TEXCOORD1;
            }; 

            sampler2D _NoiseTex;
            float4 _NoiseTex_ST;
            int _NoiseStrength;
            fixed4 _BaseColor;
            float _Speed;
            float4 _Move;

            v2g vert (appdata v)
            {
                v2g o;
                float speed1 = frac(_Time.y * _Speed  );
                float speed2 = smoothstep( 0, 1 , speed1 * (v.vertex.y + 3)* 0.3 );//y在0~10内
                float4 offset =  speed2 * _Move;
                v.vertex.xyz += offset;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _NoiseTex);
                o.progress = speed2;

                return o;
            }

            //以一个三角形为单位进行输入

            [maxvertexcount(1)] 
            void geom(point v2g input[1],inout PointStream<g2f> outStream){ 
                g2f o=(g2f)0; 

                // for(int i=1; i<_NoiseStrength; i++){
                //     float2 uv2 = (input[0].uv[0] + i, input[0].uv[1] + i);
                //     fixed4 offset = tex2Dlod(_NoiseTex, float4(uv2,0,0));
                    o.vertex = input[0].vertex;
                    // o.vertex.xyz += offset * input[0].progress; 
                    o.uv = input[0].uv; 
                    o.progress = input[0].progress; 

                    outStream.Append(o); 
                // }

            } 

            // [maxvertexcount(3)] 
            // void geom(triangle v2g input[3],inout PointStream<g2f> outStream){ 
            //     g2f o=(g2f)0; 
            //     o.vertex=input[0].vertex; 
            //     o.vertex=input[1].vertex; 
            //     o.vertex=input[2].vertex; 
                 
            //     outStream.Append(o); 
            // } 

            fixed4 frag (g2f i) : SV_Target
            {
                // fixed4 finalCol = tex2D(_MainTex, i.uv);
                fixed4 finalCol = fixed4(1, i.progress, i.progress, 0);

                return finalCol;
            }
            ENDCG
        }
    }
}
